package com.stars.empoly.vmodel

import android.app.Application
import android.text.TextUtils
import androidx.databinding.Bindable
import androidx.lifecycle.MutableLiveData
import com.stars.empoly.BR
import com.stars.empoly.utils.ChosePhotoUtils
import com.stars.empoly.utils.VerifyUtils
import com.trailer.base.base.BRepository
import com.trailer.base.base.BViewModel

class OwnerVModel(application: Application) : BViewModel<BRepository>(application) {


    var imgIDMan: MutableLiveData<String> = MutableLiveData("")
    var imgIDEmblem: MutableLiveData<String> = MutableLiveData("")
    var type: Int = 1//1:身份证正面  2:身份证背面

    var isShow: MutableLiveData<Boolean> = MutableLiveData(true)


    var isOne: MutableLiveData<Boolean> = MutableLiveData(false)
    var isTwo: MutableLiveData<Boolean> = MutableLiveData(false)
    //不完整路径
    var imgIDMan_up:String?=null
    var imgIDEmblem_up:String?=null


    @Bindable
    var name: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.name)
        }

    @Bindable
    var iDNumber: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.iDNumber)
        }


    fun choseImg(type: Int) {


        if (!isShow.value!!) {
            return
        }
        //选择照片
        this.type = type
        ChosePhotoUtils.getChosePhoto(view()!!.context(), 1)

    }

    fun toSubmit() {

        if (TextUtils.isEmpty(imgIDMan.value)) {
            toast("请上传身份证人像面图片")
            return
        }

        if (TextUtils.isEmpty(imgIDEmblem.value)) {
            toast("请上传国徽面图片")
            return
        }
        if (TextUtils.isEmpty(name)) {
            toast("请输入姓名")
            return
        }
        //验证姓名的格式

        if (!VerifyUtils.isLegalName(name!!)) {
            toast("姓名格式不对，请核实！")
            return
        }
//        //判断是否和图片上的一致
//        if(!TextUtils.isEmpty(nameID)&&(!name.equals(nameID))){
//            toast("输入姓名和身份证上姓名不一致，请核实！")
//            return
//        }

        if (TextUtils.isEmpty(iDNumber)) {
            toast("请输入身份证号")
            return
        }
        if (!VerifyUtils.isLegalId(iDNumber!!)) {
            toast("身份证格式不对，请核实！")
            return
        }
//        //判断是否和图片上的一致
//        if(!TextUtils.isEmpty(iDNumberID)&&(!iDNumber.equals(iDNumberID))){
//            toast("输入身份证号和身份证上的身份证号不一致，请核实！")
//            return
//        }

//
//        repository().rxLreq(NetEngine.service.setInfo(imgIDMan.value, imgIDEmblem.value, name, iDNumber))
//                .doOnNext {
//                    if (it.ok(true)) {
//                        var user = User.get()
//                        user!!.is_info = 2
//                        user.save()
//                        RxBus.get().post(ConfigRx.REFRESH_USER, "")
//                        (repository().context as Activity).finish()
//                    }
//                }
//                .subscribe()

    }








}
